#ifndef MSGDEALER_H
#define MSGDEALER_H

#include "MsgModPC.h"
#include <set>
using std::set;




class CMsgDealer : public CMsgModPC
{
public:
    virtual void MOnRecvMsg(unsigned int type, T_LParameter lp, const DataFlow &data)
    {
		TLVpacketer p(data);
		int com = -1;
		switch (type)
		{
		case MSG_SOCKET_CLIENT_CONNECT_FAIL:
			printf("%s: Connect Fail %s\n",
				"ClientMsgDealer", data.GetData());
			break;
		case MSG_SOCKET_CLIENT_CONNECT_OK:
			//UnmanagedSend(p);
			break;
		case MSG_SOCKET_CLIENT_HUNGUP:
			printf("%s: client socket %d hung up\n", "ClientMsgDealer", lp);
			break;
		case MSG_SOCKET_CLIENT_RECV:
			p[P_SERVER_COMMAND].GetNumber(com);
			if ( com != P_SERVER_COMMAND_ROOM )
				UnmanagedSendLocal(p);
			else 
			{
					UnmanagedSendPlayer(p);
			}
			printf("%s: Recev on socket %d, length %d\ncontent:%s\n",
				"ClientMsgDealer", lp, data.GetLength(), data.GetData());
			break;
		}
    }
};

class CBarSetter : public CMsgModPC
{
public:
	CBarSetter() { 
		//UnmanagedSendBar(0, 30, 30, 1); 
		SetSleepTime(1000);
	}
    virtual void MOnTimeOut()
	{
		UnmanagedSendBar(0, 30, 1, 0);
		UnmanagedSendBar(1, 30, 1, 0);
		UnmanagedSendBar(2, 30, 1, 0);
		UnmanagedSendBar(3, 30, 1, 0);
		UnmanagedSendBar(4, 30, 1, 0);
	}
	void StartBar(int i)
	{
		BarSet.insert(i);
	}
	void StopBar(int i)
	{
		BarSet.erase(i);
	}
	void SetTime()
	{
		if (BarSet.empty())
		{
			SetSleepTime(0);
		}
	}
private:
	std::set<int> BarSet;
};













#endif